function decimalNum(obj) {
    obj.value = obj.value.replace(/[^\d.]/g, ""); //清除"数字"和"."以外的字符
    obj.value = obj.value.replace(/^\./g, ""); //验证第一个字符是数字
    obj.value = obj.value.replace(/\.{2,}/g, "."); //只保留第一个, 清除多余的
    obj.value = obj.value.replace(".", "$#$").replace(/\./g, "").replace("$#$", ".");
    obj.value = obj.value.replace(/^(\-)*(\d+)\.(\d\d).*$/, '$1$2.$3'); //只能输入两个小数
    if (obj.value == "" || obj.value == undefined) {
        obj.value = 0
    } else {
        if (obj.value.indexOf(".") < 0 && obj.value != "") {//以上已经过滤，此处控制的是如果没有小数点，首位不能为类似于 01、02的金额
            obj.value = parseFloat(obj.value);
        }
        if (obj.value > 10 && obj.value.indexOf(".") < 0) {
            if (obj.value.length === 2) {
                obj.value = obj.value.substring(0, 1)
            } else if (obj.value.length === 3) {
                obj.value = obj.value.substring(0, 2)
            }
        } else if (obj.value > 10 && obj.value.indexOf(".") > 0) {
            obj.value = obj.value.split('.')[0]
        }
    }
}

function decimalNumTwo(obj) {
    obj.value = obj.value.replace(/[^\d.]/g, ""); //清除"数字"和"."以外的字符
    obj.value = obj.value.replace(/^\./g, ""); //验证第一个字符是数字
    obj.value = obj.value.replace(/\.{2,}/g, "."); //只保留第一个, 清除多余的
    obj.value = obj.value.replace(".", "$#$").replace(/\./g, "").replace("$#$", ".");
    obj.value = obj.value.replace(/^(\-)*(\d+)\.(\d\d).*$/, '$1$2.$3'); //只能输入两个小数
    if (obj.value == "" || obj.value == undefined) {
        obj.value = 0
    } else {
        if (obj.value.indexOf(".") < 0 && obj.value != "") {//以上已经过滤，此处控制的是如果没有小数点，首位不能为类似于 01、02的金额
            obj.value = parseFloat(obj.value);
        }

        if (obj.value > 20 && obj.value.indexOf(".") < 0) {
            if (obj.value.length === 2) {
                obj.value = obj.value.substring(0, 1)
            } else if (obj.value.length === 3) {
                obj.value = obj.value.substring(0, 2)
            }
        } else if (obj.value > 20 && obj.value.indexOf(".") > 0) {
            obj.value = obj.value.split('.')[0]
        }
    }
}

$("#cancel").click(function () {
    parent.layer.close(parent.layer.getFrameIndex(window.name))
});

$(".preoperative").on('div', '.fraction', function () {
    var preScore = 0;
    for (var i = 0; i < $(".preoperative .fraction").length; i++) {
        preScore += parseFloat($(".preoperative .fraction").eq(i).val());
    }
    $("#preScore").val(preScore.toFixed(2))
});

$(".intraOperative").on('div', '.fraction', function () {
    var intraScore = 0;
    for (var i = 0; i < $(".intraOperative .fraction").length; i++) {
        intraScore += parseFloat($(".intraOperative .fraction").eq(i).val())
    }
    $("#intraScore").val(intraScore.toFixed(2))
});

$(".postoperative").on('div', '.fraction', function () {
    var postScore = 0;
    for (var i = 0; i < $(".postoperative .fraction").length; i++) {
        postScore += parseFloat($(".postoperative .fraction").eq(i).val())
    }
    $("#postScore").val(postScore.toFixed(2))
});

$("#scoringSure").click(function () {
    var operativeList = [];
    for (var i = 0; i < $(".operativeScore").length; i++) {
        var operativeObj = {};
        var fractionList = [];
        for (var e = 0; e < $(".operativeScore").eq(i).find('.fraction').length; e++) {
            fractionList.push(parseFloat($(".operativeScore").eq(i).find('.fraction').eq(e).val()));
        }
        operativeObj.num = $("#numValue").val();
        operativeObj.number = $("#number").val();
        operativeObj.userName = $("#userName").val();
        operativeObj.type = $(".operativeScore").eq(i).find('.operativeType').html();
        operativeObj.list = fractionList;
        operativeList.push(operativeObj)
    }
    $.ajax({
        url: Feng.ctxPath + "/qualityAssurances/scoringSure",
        type: "POST",
        dataType: "json",
        contentType: "application/json",
        data: JSON.stringify(operativeList),
        success: function (data) {
            Feng.success("评分成功！");
            window.parent.QualityAssurances.table.refresh();
            parent.layer.close(parent.layer.getFrameIndex(window.name));
        },
        error: function (data) {
            alert('没有权限，请联系管理员!');
        }
    });
});

$(":radio").click(function () {
    if ($("#radio0").prop("checked")==true) {
        if (confirm("确定选择智能打分吗？")) {
            $.ajax({
                url: Feng.ctxPath + "/qualityAssurances/getScoreStatus",
                type: "post",
                data: {
                    "scoreStatus": '0',
                    "num": $("#numValue").val()
                },
                success: function (data) {
                    Feng.success('操作成功!');
                    window.parent.QualityAssurances.table.refresh();
                    parent.layer.close(parent.layer.getFrameIndex(window.name))
                }
            });
        } else {
            if ($("#radio0").prop("checked") == false) {
                $("#radio0").prop('checked', true);
                $("#radio1").prop('checked', false);
            } else {
                $("#radio1").prop('checked', true);
                $("#radio0").prop('checked', false);
            }
        }
    } else {
        var id = $(this).attr('id');
        if (confirm("确定选择人工打分吗？")) {
            $.ajax({
                url:Feng.ctxPath + "/qualityAssurances/getStatus",
                type:"post",
                data:{
                    "num": $("#numValue").val()
                },
                success:function (log) {
                    console.log(1);
                    if(log==1){
                        alert("该患者还没有人工打分，请先人工打分...")
                    }else{
                        $.ajax({
                            url: Feng.ctxPath + "/qualityAssurances/getScoreStatus",
                            type: "post",
                            data: {
                                "scoreStatus": '1',
                                "num": $("#numValue").val(),
                                "id":id
                            },
                            success: function (data) {
                                Feng.success('操作成功!');
                                window.parent.QualityAssurances.table.refresh();
                                parent.layer.close(parent.layer.getFrameIndex(window.name))
                            }
                        });
                    }
                }
            })
        } else {
            if ($("#radio0").prop("checked") == false) {
                $("#radio0").prop('checked', true);
                $("#radio1").prop('checked', false);
            } else {
                $("#radio1").prop('checked', true);
                $("#radio0").prop('checked', false);
            }
        }
    }
});

$(function () {
    if($("#scoringStatus").val()==1){
        $("#radio1").attr("checked", "checked");
    } else {
        $("#radio0").attr("checked", "checked");
    }
});